package com;

import com.projo.User;
import com.serrvice.Blog;
import com.shuxingzhuu.UserController;
import com.shuxingzhuu.UserDaoServiceIml;
import com.shuxingzhuu.lieren;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class wu {
    @Test
    public void test(){
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    //在执行getBean的时候, user已经创建好了 , 通过无参构造
        User user = (User) context.getBean("user");
      //调用对象的方法 .
      user.show();
    }


    @Test
    public void test1(){
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //在执行getBean的时候, user已经创建好了 , 通过无参构造
        User user = (User) context.getBean("user1");
        //调用对象的方法 .
        user.show();
    }

    @Test
    public void test2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //在执行getBean的时候, user已经创建好了 , 通过无参构造
        User user = (User) context.getBean("user2");
        //调用对象的方法 .
        user.show();
    }

//===================================验证作用域===========================================================================
@Test
public void test3(){
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    //在执行getBean的时候, user已经创建好了 , 通过无参构造
    Blog blog = (Blog) context.getBean("blog");
    Blog blog2 = (Blog)context.getBean("blog");
    System.out.println(blog==blog2);
}

//===================================属性注入========================================================
@Test
public void test4(){
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    //在执行getBean的时候, user已经创建好了 , 通过无参构造
    lieren lier = (lieren) context.getBean("lieren");
    System.out.println(lier.toString());

}
//=======================================注解注入
//注解注入
@Test
public  void  test5(){
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    UserController userController= (UserController) context.getBean("userController");
    userController.save();

}
}
